package com.hotSpot.chapter.two.four;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;
/**
 * 借助CGLib使方法区出现内存溢出现象
 * @author wangjunjie
 *VM :-XX:PermSize=10M -XX:MaxPermSize=10M 
 */
public class JavaMethodAreaOOM {

	public static void main(String[] args){
		while(true){
			Enhancer enhancer = new Enhancer();
			 enhancer.setSuperclass(OOMObject.class);// 设置代理目标  
			 enhancer.setUseCache(false);
		     enhancer.setCallback(new MethodInterceptor(){
		    	 public Object intercept(Object obj, Method method,Object[] args,MethodProxy proxy) throws Throwable {
		    		 return proxy.invoke(obj, args);
		    	 }
		     });// 设置回调 
		     enhancer.create();
		}
	}
	
	static class OOMObject{}
	
}


